﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Exhibition.Dao.ViewModel;
using Exhibition.Service;

namespace Exhibition.control
{
    public partial class Head : BaseControl
    {
        public TimeSpan tspan;
        StringBuilder sb = new StringBuilder();
        StringBuilder sb2 = new StringBuilder();
        public int count = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                tspan =Convert.ToDateTime( stmd.EndTime) - DateTime.Now;
                if (!(tspan.Days > 0)) {
                    djs.Visible = false;
                }
                LoadNav();
            }
        }

        private void LoadNav()
        {
            List<NavModel> mdls = CenterService.navService.GetListByPid(0);
            int i = 1;
            foreach (var m in mdls) {
                if (m.IsShow == 0)
                {
                    i++;

                    //<li><a href="#" title="展会介绍" id="nav2" onmouseover="hover(2);">展会介绍</a></li>
                    if (m.IsSingle == 0)
                    {
                        sb.AppendFormat("<li><a  title=\"{0}\" id=\"nav{1}\" onmouseover=\"hover({1},{2});\">{0}</a></li>", m.NavName, i, mdls.Count + 2, "NavDetail.aspx?tpid=" + m.Id);
                       // sb.AppendFormat("<li><a href=\"{3}\" title=\"{0}\" id=\"nav{1}\" onmouseover=\"hover({1},{2});\">{0}</a></li>", m.NavName, i, mdls.Count+2, "NavDetail.aspx?tpid=" + m.Id);
                    }
                    else
                    {
                        sb.AppendFormat("<li><a href=\"{3}\" title=\"{0}\" id=\"nav{1}\" onmouseover=\"hover({1},{2});\">{0}</a></li>", m.NavName, i, mdls.Count+2, "NewsList.aspx?tpid=" + m.Id);
                    }

                    List<NavModel> smdl = CenterService.navService.GetListByPid(m.Id);

                    //<div class="two_nav" id="hover2" style="display: none;">
                    //    <ul>
                    //        <li><a href="#" title="展会特点">展会特点</a> |&nbsp;</li>
                    //        <li><a href="#" title="组织机构">组织机构</a></li>
                    //    </ul>
                    //</div>
                    sb2.AppendFormat("<div class=\"two_nav\" id=\"hover{0}\" style=\"display: none;\">", i);
                    sb2.AppendFormat("<ul>");
                    int j = 1;
                    
                    foreach (var s in smdl)
                    {
                       
                        var shuxian=" | ";
                        if (j == smdl.Count) {

                            shuxian = "";
                        }
                        if (s.IsSingle == 0)
                        {
                            sb2.AppendFormat(" <li><a href=\"{1}\" title=\"{0}\">{0}</a>{2}</li>", s.NavName, "NavDetail.aspx?tpid=" + s.Id, shuxian);
                        }
                        else {
                            sb2.AppendFormat(" <li><a href=\"{1}\" title=\"{0}\">{0}</a>{2}</li>", s.NavName, "NewsList.aspx?tpid=" + s.Id, shuxian);
                        //    sb2.AppendFormat(" <li>{0}{1}</li>", s.NavName,   shuxian);
                        } 
                        j++;
                    }
                    //sb2.Remove(sb2.Length-1,1);
                    sb2.AppendFormat("</ul>");
                    sb2.AppendFormat("</div>");
                }
                
            }
            count = i;
            ltrAll.Text = sb.ToString();
            ltrSon.Text = sb2.ToString();

        }
    }
}